package com.cvc.tracker.es;

public class Improc implements Runnable {

	private volatile boolean pleaseStop;
	private volatile boolean resetKlt;
	public volatile int isKlt;
	public volatile int isNatural;
	
	public Improc()
	{		
		isKlt = 0;
		isNatural = 0;
	}
	

	public void tellMeToStop() {
		pleaseStop = true;
	}
	
	public void resetTrackingState() {
		resetKlt = true;
	}

	void processImage() {

		CVCTrackerActivity.cap.getImageToIM();
		if(resetKlt)
		{
			CVCTLib.resetTrackingState();
			resetKlt = false;
		}
		CVCTLib.process(isKlt,isNatural);
		setMatrix();
	}

	private void setMatrix() {
		synchronized (this) {
			CVCTLib.copyMatrixToRender();
		}
	}

	void getMatrix() {
		synchronized (this) {
			CVCTLib.getMatrixToRender();
		}
	}

	@Override
	public void run() {
		pleaseStop = false;
		try {
			while (!pleaseStop) {
				processImage();
				System.out.println(this.getClass().getName());
				Thread.sleep(10);
			}
		} catch (InterruptedException e) {
			System.out.println("ACABOU " + this.getClass().getName());
		}
	}

}
